import itertools


def permutations(s):
    """
    输入一个字符串，输出这个字符串的所有排列，并删除重复的情况

    测试用例：
    permutations('a') => ['a']
    permutations('ab') => ['ab', 'ba']
    permutations('aabb') => ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa']
    :param str:
    :return:
    """
    if len(s) == 1:
        return [s]

    result = set()

    for i in range(len(s)):
        char = s[i]

        remaining = s[:i] + s[i + 1:]

        for perm in permutations(remaining):
            result.add(char + perm)

    return list(result)


if __name__ == '__main__':
    print(permutations('a'))
    print(permutations('ab'))
    print(permutations('aabb'))
